package com.ztesoft.ossup.report.web.chart;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ztesoft.ossup.report.dao.ReportSubRepo;
import com.ztesoft.ossup.report.domain.BaseChart;
import com.ztesoft.ossup.report.domain.ReportSub;
import com.ztesoft.ossup.report.service.ChartService;
import com.ztesoft.ossup.report.service.DataPreviewService;
import com.ztesoft.ossup.report.web.BaseController;

@Controller
@RequestMapping("/report/chart")
public class ChartController extends BaseController {

	@Autowired
	ChartService chartService;

	@Autowired
	DataPreviewService dataPreviewService;

	@Autowired
	ReportSubRepo reportSubRepo;

	@RequestMapping(value = "/chartDemo/{reportId}", method = RequestMethod.GET)
	public String chartDemo(HttpServletRequest request, @PathVariable Long reportId) {
		return "/chart/chartDemo";
	}

	@RequestMapping(value = "/loadLineChartData/{reportId}", method = RequestMethod.GET)
	@ResponseBody
	public String loadLineChartData(@PathVariable Long reportId, HttpServletRequest request) {

		Map emptyMap = new HashMap<>();
		Map<String, Object> map = chartService.getChartData(reportId, emptyMap);
		ResponseEntry responseEntry = new ResponseEntry(SUCCESS);
		responseEntry.setDetail(map);
		return responseEntry.getJSON();
	}

	@RequestMapping(value = "/loadPieChartData", method = RequestMethod.GET)
	@ResponseBody
	public String loadPieChartData(HttpServletRequest request) {
		Map<String, Object> map = chartService.getPieChartData();
		ResponseEntry responseEntry = new ResponseEntry(SUCCESS);
		responseEntry.setDetail(map);
		return responseEntry.getJSON();
	}

	@RequestMapping(value = "/loadBarChartData", method = RequestMethod.GET)
	@ResponseBody
	public String loadBarChartData(HttpServletRequest request) {

		Map<String, Object> map = chartService.getLineChartData();

		ResponseEntry responseEntry = new ResponseEntry(SUCCESS);
		responseEntry.setDetail(map);
		return responseEntry.getJSON();
	}

}
